// 生成docDirs.js
const DEST_PATH = 'public/docDirs.js'

import walkSync from 'walk-sync';
import fs from  'fs'

import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const baseFolder = 'public/server1/docs'
const paths = walkSync(join(__dirname, baseFolder)).filter(v => !v.startsWith('.'))
console.log(paths)
let text = ''

paths.forEach(path => {
  let p = join(baseFolder, path)
  let state = fs.lstatSync(p)
  if (state.isFile()) {

    // console.log(fileContent)
    text = text + `
  {
    label: '${path}',
    value: '/server1/docs/${path}'
  },`
  }
})

let jsTpl = function (v) {
  return `export default [${v}
]`
}

let exportJsStr = jsTpl(text)
// console.log(jsTpl(text))


fs.writeFileSync(join(__dirname, DEST_PATH), exportJsStr)
